package com.yft.data.util;

import java.util.Date;
import java.util.List;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class DataConfig {

	/**
	 * 根据给定的日期类型返回sql语句
	 * 
	 * @param datetype
	 * @return
	 */
	public static String getDateType(int datetype) {
		switch (datetype) {
		case 1:
			return "date=? and ";
		case 2:
			return "datediff(CURDATE(),date)<3 and ";
		case 3:
			return "datediff(CURDATE(),date)<7 and ";
		case 4:
			return "datediff(CURDATE(),date)<30 and ";
		}
		return "datediff(CURDATE(),date)<7 and ";
	}

	/**
	 * 根据约定好的pricetype，返回查询price的条件
	 * 
	 * @param pricetype
	 * @return
	 */
	public static String getPriceType(int pricetype) {
		// 1 500以下 2 500-1000 3 1000-2000 4 2000-3000 5 3000-5000
		switch (pricetype) {
		case 1:
			return "price<500 and ";
		case 2:
			return "price>500 and price<1000 and ";
		case 3:
			return "price>1000 and price<2000 and ";
		case 4:
			return "price>2000 and price<3000 and ";
		case 5:
			return "price>3000 and price<5000 and ";
			// 6 5000-8000 7 8000以上 51 50w以下 52 50w-100w 53 100w-200w 54 200w以上
		case 6:
			return "price>5000 and price<8000 and ";
		case 7:
			return "price>8000 and ";
		case 51:
			return "price<500000 and ";
		case 52:
			return "price>500000 and price<1000000 and ";
		case 53:
			return "price>1000000 and price<2000000 and ";
		case 54:
			return "price>2000000 and ";
		}
		return "";
	}

	public static String getSpaceType(int spacetype) {
		// 1 50㎡以下 2 50-100㎡ 3 100-150㎡ 4 150-200㎡ 5 200㎡以上
		switch (spacetype) {
		case 1:
			return "space<50 and ";
		case 2:
			return "space>50 and space<100 and ";
		case 3:
			return "space>100 and space<150 and ";
		case 4:
			return "space>150 and space<200 and ";
		case 5:
			return "space>200 and ";
		}

		return "";
	}

	public static String getRoomType(int roomtype) {
		//1 1室 2 2室3 3室 4 4室 5 5室 6 6室 7 7室 8 8室
		switch (roomtype) {
		case 1:
			return "(roomType like '%1室%' or roomType like '%一室%' or roomType like '%单间%') and ";
		case 2:
			return "(roomType like '%2室%' or roomType like '%二室%') and ";
		case 3:
			return "(roomType like '%3室%' or roomType like '%三室%') and ";
		case 4:
			return "(roomType like '%4室%' or roomType like '%四室%') and ";
		case 5:
			return "(roomType like '%5室%' or roomType like '%五室%') and ";
		case 6:
			return "(roomType like '%6室%' or roomType like '%六室%') and ";
		case 7:
			return "(roomType like '%7室%' or roomType like '%七室%') and ";
		case 8:
			return "(roomType like '%8室%' or roomType like '%八室%') and ";
		}

		return "";
	}

	public static void getPriceTypeMongo(Query q, int pricetype) {
		// 1 500以下 2 500-1000 3 1000-2000 4 2000-3000 5 3000-5000
		switch (pricetype) {
			case 1:
				q.addCriteria(Criteria.where("price").lt(500));
				break;
			case 2:
				q.addCriteria(Criteria.where("price").gt(500).lt(1000));
				break;
			case 3:
				q.addCriteria(Criteria.where("price").gt(1000).lt(2000));
				break;
			case 4:
				q.addCriteria(Criteria.where("price").gt(2000).lt(3000));
				break;
			case 5:
				q.addCriteria(Criteria.where("price").gt(3000).lt(5000));
				break;
				// 6 5000-8000 7 8000以上 51 50w以下 52 50w-100w 53 100w-200w 54 200w以上
			case 6:
				q.addCriteria(Criteria.where("price").gt(5000).lt(8000));
				break;
			case 7:
				q.addCriteria(Criteria.where("price").gt(8000));
				break;
			case 51:
				q.addCriteria(Criteria.where("price").gt(500000));
				break;
			case 52:
				q.addCriteria(Criteria.where("price").gt(500000).lt(1000000));
				break;
			case 53:
				q.addCriteria(Criteria.where("price").gt(1000000).lt(2000000));
				break;
			case 54:
				q.addCriteria(Criteria.where("price").gt(2000000));
				break;
		}
	}

	public static void getSpaceTypeMongo(Query q, int spacetype) {
		// 1 50㎡以下 2 50-100㎡ 3 100-150㎡ 4 150-200㎡ 5 200㎡以上
		switch (spacetype) {
			case 1:
				q.addCriteria(Criteria.where("space").lt(50));
				break;
			case 2:
				q.addCriteria(Criteria.where("space").gt(50).lt(100));
				break;
			case 3:
				q.addCriteria(Criteria.where("space").gt(100).lt(150));
				break;
			case 4:
				q.addCriteria(Criteria.where("space").gt(150).lt(200));
				break;
			case 5:
				q.addCriteria(Criteria.where("space").gt(200));
				break;
		}
	}

	public static void getRoomTypeMongo(Query q, int roomtype, List<Criteria> orList) {
		//1 1室 2 2室3 3室 4 4室 5 5室 6 6室 7 7室 8 8室
		Criteria c1;
		switch (roomtype) {
			case 1:
				c1 = new Criteria();
				
				c1.orOperator(
						new Criteria("roomType").regex(".*?"+"单间"+".*"),
						new Criteria("roomType").regex(".*?"+"一室"+".*"),
						new Criteria("roomType").regex(".*?"+"1室"+".*")
						);
				q.addCriteria(c1);
				break;
			case 2:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"二室"+".*"),new Criteria("roomType").regex(".*?"+"2室"+".*"));
				q.addCriteria(c1);
				break;
			case 3:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"三室"+".*"),new Criteria("roomType").regex(".*?"+"3室"+".*"));
				q.addCriteria(c1);
				break;
			case 4:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"四室"+".*"),new Criteria("roomType").regex(".*?"+"4室"+".*"));
				q.addCriteria(c1);
				break;
			case 5:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"五室"+".*"),new Criteria("roomType").regex(".*?"+"5室"+".*"));
				q.addCriteria(c1);
				break;
			case 6:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"六室"+".*"),new Criteria("roomType").regex(".*?"+"6室"+".*"));
				q.addCriteria(c1);
				break;
			case 7:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"七室"+".*"),new Criteria("roomType").regex(".*?"+"7室"+".*"));
				q.addCriteria(c1);
				break;
			case 8:
				c1 = new Criteria();
				c1.orOperator(new Criteria("roomType").regex(".*?"+"八室"+".*"),new Criteria("roomType").regex(".*?"+"8室"+".*"));
				q.addCriteria(c1);
				break;
		}
	}

	public static void getDateTypeMongo(Query q, int datetype) {
		switch (datetype) {
			case 1:
				q.addCriteria(Criteria.where("date").gt(StringUtil.getDateBefore(new Date(), 1)));
				break;
			case 2:
				q.addCriteria(Criteria.where("date").gt(StringUtil.getDateBefore(new Date(), 3)));
				break;
			case 3:
				q.addCriteria(Criteria.where("date").gt(StringUtil.getDateBefore(new Date(), 7)));
				break;
			case 4:
				q.addCriteria(Criteria.where("date").gt(StringUtil.getDateBefore(new Date(), 30)));
				break;
			default:
				//q.addCriteria(Criteria.where("date").gt(StringUtil.getDateBefore(new Date(), 7)));
				break;
		}
		
	}



}
